#ifndef IP_COMMON_H
#define IP_COMMON_H

#include <memory>
#include <inttypes.h>

#include "eth_impl.h"
#include "arp_impl.h"
#include "endpoint_addr.h"

#define MAX_INET_PAYLOAD   576

namespace usnet {

enum class InetDSCP : uint8_t {

};

class BaseIP {
public:
    virtual ~BaseIP()
    {
        eth_impl_ = nullptr;
        fb_mgr_ = nullptr;
    }

    BaseIP(const PPT proto, EndpointAddr* laddr, EndpointAddr* raddr):
        proto_ { proto },
        laddr_ { laddr },
        raddr_ { raddr }
    {
        // nothing to do
    }

    virtual std::shared_ptr<FrameBufMgr> PrefillHeader() = 0;
    virtual void SendPacket() = 0;
    virtual bool RecvPacket() = 0;
    virtual uint32_t GetHeaderSize() const = 0;
    virtual uint16_t CheckSum(const FrameBuf* fb) = 0;
    
protected:
    bool InitARPImpl();
    bool InitEthImpl();
    
    const PPT       proto_ { };
    EndpointAddr*   laddr_ { nullptr };
    EndpointAddr*   raddr_ { nullptr };
    const Ifconfig* ifcfg_ { nullptr };
    std::unique_ptr<EthImpl> eth_impl_      { nullptr };
    std::shared_ptr<FrameBufMgr> fb_mgr_    { nullptr };
};
} // end of namespace usnet
#endif